package org.fly.utils.wx;

import org.fly.bean.WxSetting;
import org.fly.contants.WxConstant;
import org.fly.utils.HttpClientUtil;

/**
 * Created by rongzhao.zhu on 2018/4/22.
 */
public class WxUtils {

    public static boolean auth(WxSetting wxSetting,String cbUrl,String cbParam){
        boolean flag = false;
        try{
            String url =  buildAuthUrl(wxSetting,cbUrl,cbParam);
            String result = HttpClientUtil.sendHttpPost(url,"");
            flag = true;
        }catch (Exception e){
            e.printStackTrace();
        }

        return flag;
    }

    public static String buildAuthUrl(WxSetting wxSetting,String cbUrl,String cbParam){
        String  authUrl = WxConstant.wxAuthUrl;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(authUrl);
        stringBuilder.append("?appid=");
        stringBuilder.append(wxSetting.getAppId());
        stringBuilder.append("&redirect_uri=");
        stringBuilder.append(cbUrl);
        stringBuilder.append("&response_type=code&scope=snsapi_userinfo");
        stringBuilder.append("&state=");
        stringBuilder.append(cbParam);
        stringBuilder.append("#wechat_redirect");
        return stringBuilder.toString();
    }

}
